<template>
  <div class="footsteps">
    <p class="text1">-烹饪步骤-</p>
    <div class="steps">
      <p class="text2">点击步骤进入烹饪模式</p>
      <ul>
        <li v-for="(item, index) in stepList" :key="item.id">
          <p>
            <span class="steps-text1">步骤{{ index + 1 }}</span>
            <span class="steps-text2">/{{ stepList.length }}</span>
          </p>
          <div class="steps-img" v-if="item.imageid">
            <img :src="`http://pic.angelboy.cn/web/${item.imageid}.jpg`" alt="" @click="previewImage(stepList, index)" />
          </div>
          <p class="text3">{{ item.details }}</p>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { ImagePreview } from 'vant'
export default {
  props: ['stepList'],
  data() {
    return {
      images: [] //预览图片的数组
    }
  },
  methods: {
    // 图片预览
    previewImage(stepList, index) {
      if (this.images.length == 0) {
        stepList.forEach((step) => {
          const img = `http://pic.angelboy.cn/web/${step.imageid}.jpg`
          this.images.push(img)
        })
      }

      ImagePreview(this.images, index)
    }
  }
}
</script>

<style lang="less" scoped>
.footsteps {
  margin-top: 30px;
  p {
    text-align: center;
  }

  .text1 {
    font-size: 15px;
  }

  .text2 {
    padding: 10px 0 15px 0;
    font-size: 13px;
    color: #ababab;
  }

  .steps {
    padding: 0 10px;

    ul {
      li {
        p {
          text-align: left;
          margin: 10px 0;

          .steps-text2 {
            font-size: 12px;
            color: #ababab;
          }
        }

        .steps-img {
          width: 100%;
          height: 300px;
          border-radius: 5px;
          //   background-color: black;

          img {
            width: 100%;
            height: 100%;
            border-radius: 5px;
            display: block;
          }
        }

        .text3 {
          margin: 10px 0 20px 0;
        }
      }
    }
  }
}
</style>
